import { Injectable } from '@nestjs/common';
import { CreateFeatureScenarioDto } from './dto/create-feature-scenario.dto';
import { UpdateFeatureScenarioDto } from './dto/update-feature-scenario.dto';
import { PrismaService } from 'src/prisma/prisma.service';


@Injectable()
export class FeatureScenarioService {

  constructor( private prisma:PrismaService){}

  // 创建
  async create(data: CreateFeatureScenarioDto) {
    
    return await this.prisma.featureScenario.create({
      data:data
    })
  }
  
  async deleteByFid(fid:number){
    return await this.prisma.featureScenario.deleteMany({
      where:{
        fid:fid,
      }
    })
  }

    // 根据fid查询多条
    async findManyByFid(fid:number){
      return await this.prisma.featureScenario.findMany({
        where:{
          fid:fid
        }
      })
    }

    // 根据sid 查询
    async findManyBySid(sid:number){
      return await this.prisma.featureScenario.findMany({
        include:{
          feature:true
        },
        where:{
          sid
        }
      })
    }

    async remove(fid: number, sid :number) {
      return await this.prisma.featureScenario.deleteMany({
        where:{
          fid:fid,
          sid:sid
        }
      })
    }


    async updateSort(fid:number, sid:number,  sort:number){
      // 因为prisma中的update强制使用id来更新, 所以这里使用udpateMany取巧
      return await this.prisma.featureScenario.updateMany({
        where:{
          fid, sid
        },
        data:{
          sort
        }
      })
    }

}
